Home:ALL Converter>Bluetooth headphones button event detection in javascript

Bluetooth headphones button event detection in javascript

Ask Time:2018-11-25T19:55:38         Author:Shaharyar Kirmani

Json Formatter

I am building a web app where I detect the headphones button event. I succeeded in capturing headphones button event when they are plugged in. Now I am trying to capture Bluetooth headphones next button event. Any help on this please?

Code for headphone button detection.

 document.addEventListener('volumeupbutton', () => {
   //Do something here
 }, false);

I need something similar to this.

Author:Shaharyar Kirmani,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53467169/bluetooth-headphones-button-event-detection-in-javascript
Akansh :

You can use keydown and keyup events for implementing the long press functionality. \n\n\r\n\r\n// Imprementation of Long Press\r\n\r\nconst longPressTime = 1500;\r\nlet keyDownTimeout;\r\ndocument.addEventListener('keydown', e => {\r\n if (keyDownTimeout) {\r\n return;\r\n }\r\n keyDownTimeout = setTimeout(() => {\r\n // button was held for 1500ms, consider it a long-press\r\n if (e.code === 'ArrowUp') {\r\n console.log(\"Action Performed\");\r\n // do long-press action\r\n } else {\r\n console.log(\"Other action performed\");\r\n }\r\n }, longPressTime);\r\n});\r\n\r\ndocument.addEventListener('keyup', e => {\r\n clearTimeout(keyDownTimeout);\r\n keyDownTimeout = 0;\r\n});\r\nPress any key",
2019-08-06T07:09:15
yy